// components/like/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    like: {
      type: Boolean
    },
    count: {
      type: Number
    },
    readOnly: {
      type: Boolean
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    yesSrc: "/components/images/like.png",
    noSrc: "/components/images/like@dis.png"
  },
 
  /**
   * 组件的方法列表
   */
  methods: {
    onLike(event) {
      if (this.properties.readOnly){
        return;
      }
      let like = this.properties.like,
        count = this.properties.count;
      count = like ? count - 1 : count + 1;

      this.setData({
        like: !like,
        count
      });

      // 自定义事件 通知页面 用户点击了事件 
      let behavior = this.properties.like ? 'like' : 'cancel';
      // 激活事件
      this.triggerEvent('like', {
        behavior
      }, {})

      // var myEventDetail = {
      // } // detail对象，提供给事件监听函数
      // var myEventOption = {} // 触发事件的选项
      // this.triggerEvent('myevent', myEventDetail, myEventOption)

    }
  }
})